<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css"
	href="view/bootstrap-3.3.5/css/bootstrap.css" />
<link rel="stylesheet" type="text/css"
	href="view/bootstrapvalidator/css/bootstrapValidator.css" />
<script charset="utf-8" src="view/jquery/jquery-1.10.2.min.js"></script>
<script charset="utf-8" src="view/bootstrap-3.3.5/js/bootstrap.js"></script>
<script charset="utf-8"
	src="view/bootstrapvalidator/js/bootstrapValidator.js"></script>
</head>
<body>
	<div class="container">
		<form role="form" action="juese/updatequanxiang" method="post"
			class="form-horizontal" id="myform">
			<input type="hidden" name="oid" value="${requestScope.role.oid}">
			<input type="hidden" id="qxid" name="qxid">
			<table class="table table-condensed">
				<caption>对${requestScope.role.roleName}的权限管理</caption>
				<c:forEach items="${requestScope.functions}" var="f">
					<tr style="background-color: #66FFFF">
						<td><input type="checkbox" name="ck" id="f${f.oid}"
							value="${f.oid}" onclick="quan(${f.oid})"
							<c:forEach items="${requestScope.role.functions}" var="role">
                      <c:if test="${role.oid==f.oid}">checked</c:if>
                    </c:forEach>>
							${f.functionName}</td>
					</tr>
					<c:forEach items="${f.qxFunctions}" var="qf">
						<tr>
							<td>
							&nbsp;&nbsp;
							<input type="checkbox" class="z${f.oid}" name="ck"
								value="${qf.oid}"
								}
                                        <c:forEach items="${requestScope.role.functions}" var="role">
                                        <c:if test="${role.oid==qf.oid}">checked</c:if>
                                        </c:forEach>
								onclick="dan(${f.oid})"> ${qf.functionName}</td>
						</tr>
					</c:forEach>
				</c:forEach>
				<tr>
					<td><input type="button" id="btn" class="btn btn-primary"
						value="提交"> <input type="button" id="btn2"
						class="btn btn-default" value="返回"></td>
				</tr>
			</table>
		</form>
	</div>
</body>
<script type="text/javascript">
function quan(oid){
	
	$(".z"+oid).prop("checked",$("#f"+oid)[0].checked);
}

	$("#btn").click(function() {
		var ch="";
		$('input[type="checkbox"]:checked').each(function(){
			var txt = $(this).val();
			ch = ch + ":" + txt;
		});
		var qxid = $("#qxid").val(ch.slice(1));
		$("#myform")[0].submit();
	});	
	
	$("#btn2").click(function(){
		window.location.href="juese/selectJueSe";
	});
	
	var isallcheck=true;//所有子选框选中的标记
	function dan(oid){
		$(".z"+oid).each(function(i,o){
			if(!$(o).prop("checked")){
				isallcheck=false;
				return;
			}
		});
		if(!isallcheck){
			$("#f"+oid).prop("checked",isallcheck);
		}else{
			$("#f"+oid).prop("checked",isallcheck);
		}
		isallcheck=true;
	}
</script>
</html>
